package huawei.ran;

import java.util.Arrays;
import java.util.Scanner;

/**
 * https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/
 */
public class J03 {
    public static void main(String[] args) {
        System.out.println(lengthOfLongestSubstring("tmmzuxt"));
    }
    public static int lengthOfLongestSubstring(String s) {
        char[] data =s.toCharArray();
        int[] cache =new int[128];
        int maxLen = 0;
        int left = 0;
        for(int i=0;i<data.length ;i++){
            char c = data[i];
            if(cache[c]==0){
                cache[c]++;
            }else {
                maxLen=Math.max(maxLen,i-left);
                while (data[left]!=c){
                    cache[data[left]]--;
                    left++;
                }
                left++;
            }
        }
        maxLen=Math.max(maxLen,data.length-left);
        return maxLen;
    }
}
